package pkg.hicph.org;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;


public class EventScreen extends Activity implements OnClickListener  {
    
    public TextView eventInfo, eventTitle;
    public Button cancelButton;


	@Override
	public void onCreate(Bundle savedInstanceState) {
	  super.onCreate(savedInstanceState);
	  
	  requestWindowFeature(Window.FEATURE_NO_TITLE);
      getWindow().setFlags(
      WindowManager.LayoutParams.FLAG_FULLSCREEN,
      WindowManager.LayoutParams.FLAG_FULLSCREEN);
	  
	  setContentView(R.layout.eventscreen);
	  
	  registerViews();
	  setupOnClickListeners();
	  
//	  this.setTitle("You just found this place:");
	  
	  
	  
	  if(Utils.gamePhase == Utils.END_GAME_SCREEN){
		  
		  int aux = Utils.achievedInSession + 1;
		  
		  Utils.currentDay++;
		  eventTitle.setText("Day "+Utils.currentDay+" finished.\n\nYou have "+ aux +" new memories.");
		  eventInfo.setText(Utils.player.dayStory);
		  cancelButton.setVisibility(0);
		  cancelButton.setText("Back to Menu");
		  
		  
		  Utils.saveEventsPrefs(this);
		  
//		  eventTitle.setText("Are yENDou sure you will sleep here?");
//		  eventInfo.setText("Remember, you need to be safe to spend the night. If you sleep somewhere too exposed or busy, the chances of something bad happening get much higher.");
//		  cancelButton.setVisibility(0);
	  }
	  else {
		  
		  
		  if(Utils.activeEvent.type.equalsIgnoreCase("story")){
			  eventTitle.setText("A real story: your friend " + Utils.activeEvent.name + ".");
			  eventInfo.setText(Utils.activeEvent.description);
		  }
		  
		  
		  
		  
//		  eventTitle.setText("After eating, you feel really tired!");
//		  eventInfo.setText("You had some food and now you feel really tired. This area is far from the shelters you would go, and you don't want to go too far. You need to find a good, safe place to sleep around here tonight.");
	  }

	  
	}
	
	
//	private void loadPrefs() {
//		
//		String actionName;
//		
//    	preferences  = getSharedPreferences(PREF_FILE, MODE_PRIVATE);
//    	
//    	actionName = preferences.getString("nextActionName", "");
//    	
//    	Log.d("DIALOG","loaded: " + actionName);
//    	
//    	actionToPerform = Utils.nextAction;
//    	
//    	actionToPerform = Utils.getActionByName(actionName);
//    	Log.d("DIALOG","action: " + actionToPerform.name);
//        
//	}
	
	
	private void registerViews() {
			
		 cancelButton = (Button) this.findViewById(R.id.event_cancel_button);
		 eventInfo = (TextView) this.findViewById(R.id.event_info);
		 eventTitle = (TextView) this.findViewById(R.id.event_title);
	}

	
	public void setupOnClickListeners() {
        
		cancelButton.setOnClickListener(this);

    }
    
	
    public void onClick(View V) {
    	
    	switch(V.getId()) {
    		
    	case R.id.event_cancel_button:

    		
    		if(Utils.gamePhase == Utils.END_GAME_SCREEN){
    			  
    			Intent menuIntent = new Intent(this, IntroMenu.class);
    	     	this.startActivity(menuIntent);

    		  }
    		  else {
    			  
//    			  eventTitle.setText("After eating, you feel really tired!");
//    			  eventInfo.setText("You had some food and now you feel really tired. This area is far from the shelters you would go, and you don't want to go too far. You need to find a good, safe place to sleep around here tonight.");
    		  }
    		
    		
    		// CLOSES THE DIALOG
    		this.finish();
    		
    		break;
    		
    		
    	}

    }


}





